<?php
// +----------------------------------------------------------------------
// | Yzncms [ 御宅男工作室 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018 http://yzncms.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 御宅男 <530765310@qq.com>
// +----------------------------------------------------------------------

// +----------------------------------------------------------------------
// | 快手页面配置
// +----------------------------------------------------------------------
namespace app\admin\controller;

use app\common\controller\Adminbase;
use app\common\model\KuaiShouConfigModel;
use app\common\model\KuaiShouModel;

class KuaiShouConfig extends Adminbase
{

    //初始化
    protected function initialize()
    {
        parent::initialize();
        //移除HTML标签
        $this->request->filter('trim,strip_tags,htmlspecialchars');
        $this->modelClass = new KuaiShouModel;
    }

    //后台首页
    public function index()
    {
        if ($this->request->isPost()) {
            $this->token();
            $data = $this->request->post('row/a');
            $time = date('Y-m-d H:i:s');
            foreach ($data as $name => $value) {
                KuaiShouConfigModel::update([
                    KuaiShouConfigModel::VALUE => $value,
                    KuaiShouConfigModel::UPDATE_TIME => $time,
                ], [KuaiShouConfigModel::NAME => $name]);
            }
            $this->success('设置更新成功');
        }
        //获取配置
        $config = KuaiShouConfigModel::column(KuaiShouConfigModel::VALUE, KuaiShouConfigModel::NAME);
        $this->assign([
            'config' => $config,
        ]);
        return $this->fetch();
    }

}
